package com.zxbg.dao;

import com.zxbg.domain.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleDao {
    @Select("select * from role where (name like #{KeyWord} or code like #{KeyWord}) and tenant_id = #{tenant_id}")
    public List<Role> getAllRole(@Param("KeyWord") String KeyWord, @Param("tenant_id") Integer tenant_id);

    @Select("select * from role where code = #{code} and tenant_id = #{tenant_id}")
    public Role getRoleByCode(@Param("code") String code, @Param("tenant_id") Integer tenant_id);

    @Insert("insert into role values(#{code}, NOW(), #{creator_id}, #{describe}, #{number_ceil}, null, 1, #{name}, #{partner_id}, #{tenant_id})")
    public int addRole(Role role);

    @Update("update role set `describe` = #{describe}, number_ceil = #{number_ceil}, name = #{name}, partner_id = #{partner_id} where code = #{code}")
    public int editRole(Role role);

    @Update("update role set `status` = 0 where code = #{code} and tenant_id = #{tenant_id}")
    public int stopRole(@Param("code") String code, @Param("tenant_id") Integer tenant_id);

    @Update("update role set `status` = 1 where code = #{code} and tenant_id = #{tenant_id}")
    public int runRole(@Param("code") String code, @Param("tenant_id") Integer tenant_id);

    @Delete("delete from role where code = #{code} and tenant_id = #{tenant_id}")
    public int deleteRole(@Param("code") String code, @Param("tenant_id") Integer tenant_id);

    @Update("update role set authority_id = #{authority_id} where code = #{code} and tenant_id = #{tenant_id}")
    public int setAuthByRoleCode(@Param("code") String code, @Param("authority_id") String authority_id, @Param("tenant_id") Integer tenant_id);
}